package com.example.springbootdemo.aware;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class AtBeanAware implements BeanNameAware, ApplicationContextAware, InitializingBean {
  @Override
  public void setBeanName(String name) {
    log.info("current bean name: {}",name);
  }

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    log.info("current context:{}",applicationContext);
  }

  @Override
  public void afterPropertiesSet() throws Exception {
    log.info("current bean initialed");
  }

  @Bean
  public BeanFactoryPostProcessor processor(){
    return beanFactory -> log.info("执行 processor");
  }
}
